set more off 
clear

/* load auxiliary progs

also uses est2tex package by Muendler http://econ.ucsd.edu/muendler/docs/stata/est2tex.html
*/
run programs.do



local vars="hetero nop seat pool ballot lnw " 

use results, clear
** rename variables ***
rvars /* rvars is a program in programs.do */
drop if belgium==1
    
borjas b_cons `vars', dvste(se_cons)
cap est2vec table2s, e(r2 F) vars(`vars' _cons) replace name(base`i')

borjas b_educ `vars', dvste(se_educ)
cap est2vec table2s, addto(table2s)

borjas b_male `vars', dvste(se_male)
cap est2vec table2s, addto(table2s)

borjas b_age1 `vars', dvste(se_age1)
cap est2vec table2s, addto(table2s)

borjas b_age2 `vars', dvste(se_age2)
cap est2vec table2s, addto(table2s)


cap est2tex table2s, preserve mark(starb) fancy replace label levels(90 95 99)


use meanreg, clear
rvars /* rvars is a program in programs.do */
local vars="A2003 A2001 `vars' "



forval i=1/10 {
    gen b_cons`i'=b_cons
}

reg b_cons1 `vars' `robust'


cap est2vec tableprop`type', e(r2 F) vars(`vars' _cons) replace name("_")

**just for display - with belgium dummy
reg b_cons2 `vars' belgium `robust'

drop if belgium==1

reg b_cons2 `vars' `robust'

cap est2vec tableprop`type', addto(tableprop`type')



use baseeduc, clear
rvars /* rvars is a program in programs.do */
drop if belgium==1
forval i=1/3 {
    reg b_cons `vars'  if baseeduc==`i' `robust'
	cap est2vec tableprop`type', name(base`i') addto(tableprop`type')
    }



cap est2tex tableprop`type', preserve mark(starb) fancy replace label levels(90 95 99) collabels(with.belgium no.belgium educ.low educ.mid educ.high)


/* format the pdf table */
cap shell /sw/bin/pdflatex tables
cap shell open tables.pdf
